package com.gr.staffpm.pages.dashboard;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountHybrid;

import com.gr.staffpm.StaffPMWebPage;
import com.gr.staffpm.js.StaffPMJSScope;
import com.gr.staffpm.pages.dashboard.gadgets.ActivityGadget;
import com.gr.staffpm.pages.dashboard.gadgets.MyAssignedTasksGadget;
import com.gr.staffpm.pages.dashboard.gadgets.RecentFeedbackGadget;
import com.gr.staffpm.pages.dashboard.gadgets.TasksDueGadget;
import com.gr.staffpm.properties.PropertiesController;

@MountHybrid
@MountPath(path = "secure/Dashboard")
public class Dashboard extends StaffPMWebPage implements IHeaderContributor {

    private final GadgetContainer gadgetContainer = new GadgetContainer("gadgetContainer");

    public Dashboard() {
        super();
        super.onBeforeRender();

        add(new FeedbackPanel("feedback"));

        boolean feedbackOnly = Boolean.parseBoolean(PropertiesController.getInstance().getProperty("feedback.module.only", "false"));

        gadgetContainer.addGadget("Recent Feedback", new RecentFeedbackGadget(Gadget.contentId), GadgetContainer.ALIGNMENT.LEFT, 3);
        if (!feedbackOnly)
            gadgetContainer.addGadget("Next 10 tasks due in 30 days", new TasksDueGadget(Gadget.contentId), GadgetContainer.ALIGNMENT.LEFT, 1);
        gadgetContainer.addGadget("Activity Stream", new ActivityGadget(Gadget.contentId), GadgetContainer.ALIGNMENT.CENTER, 4);
        if (!feedbackOnly)
            gadgetContainer.addGadget("My Assigned Tasks", new MyAssignedTasksGadget(Gadget.contentId), GadgetContainer.ALIGNMENT.RIGHT, 1);

        add(gadgetContainer);
    }

    @Override
    public String getTitle() {
        return "Dashboard - StaffPM";
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        response.renderJavascriptReference(new ResourceReference(StaffPMJSScope.class, "dashboard.js"));
    }
}
